//
//  PickNumFC3DViewController.m
//  PlayBall
//
//  Created by Sun Fanglei on 13-3-18.
//
//

#import "JddPickNumFC3DViewController.h"
#import "JddViewControllerManager.h"
#import "JddCommonFunction.h"
#import "NoticeViewController.h"
#import "FloatLayer.h"
@interface JddPickNumFC3DViewController (){
    NSInteger _floatLayerIndex;
    FloatLayer *_layer;
    NSMutableArray *_playMethodArr;
}

@end

@implementation JddPickNumFC3DViewController

SHARED_VIEW_CONTROLLER_IMPLEMENT(JddPickNumFC3DViewController);

@synthesize label1;
@synthesize label2;
@synthesize label3;
@synthesize playIDnameLabel;
@synthesize playIDTips;
@synthesize issueCodeLabel;
@synthesize remainTimeLabel;
@synthesize zhushuLabel;
@synthesize moneyLabel;
@synthesize currentLotteryIssue;
@synthesize firstImagebg;

int playtypeID;


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if ([alertView.message isEqualToString:@"您还没有登录，请先登录"]) {
        if (buttonIndex == 0) {
            zhushuLabel.text = @"0注";
            moneyLabel.text = @"0彩豆";
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOGIN fromController:self withObject:nil withObject2:nil];
        }
    }
}

-(void)numberButtonClick:(id)sender{
    UIButton *button = sender;
    [button setSelected:![button isSelected]];
    if (button.tag == 11) {
        if ([button isSelected]) {
            [lotteryNumber addBallNumber:[button.titleLabel.text intValue]];
        }else{
            [lotteryNumber removeBallNumber:[button.titleLabel.text intValue]];
        }
    }else if (button.tag == 22){
        if ([button isSelected]) {
            [lotteryNumber add2BallNumber:[button.titleLabel.text intValue]];
        }else{
            [lotteryNumber remove2BallNumber:[button.titleLabel.text intValue]];
        }
    }else if (button.tag == 33){
        if ([button isSelected]) {
            [lotteryNumber add3BallNumber:[button.titleLabel.text intValue]];
        }else{
            [lotteryNumber remove3BallNumber:[button.titleLabel.text intValue]];
        }
    }
    if([button isSelected]){
        [JddCommonFunction animationViewWithZoomOutIn:button delaySecond:0];
    }
    [self countMoney];
}

-(void)countMoney{
    NSInteger tempCount = 0;
    switch (playtypeID) {
        case 602://直选
            tempCount = [[lotteryNumber BallArray] count]*[[lotteryNumber SecondBallArray] count]*[[lotteryNumber ThirdBallArray] count];
            break;
        case 605://组选三
            tempCount = [[lotteryNumber BallArray] count]*([[lotteryNumber BallArray] count] - 1);
            break;
        case 604://组选六
            if ([[lotteryNumber BallArray] count] > 2) {
                tempCount = [JddCommonFunction recurseBallNumber:[[lotteryNumber BallArray] count]combinationNumber:3];
            }
            break;
        default:
            break;
    }
    zhushuLabel.text = [NSString stringWithFormat:@"%d注",tempCount];
    moneyLabel.text = [NSString stringWithFormat:@"%d彩豆",tempCount*2];
}


-(void)selectMatchFC3D:(NSString *)value{
    if ([value isEqualToString:@"直选"]) {
        playtypeID = 602;
        playIDnameLabel.text = @"直选";
        playIDTips.text = @"所选号码与开奖号码按位数全部相同即中1,040彩豆";
    }else if ([value isEqualToString:@"组选三"]){
        playtypeID = 605;
        playIDnameLabel.text = @"组选三";
        playIDTips.text = @"最少选择2个数字，猜对开奖号(顺序不限)即中346彩豆";
    }else if ([value isEqualToString:@"组选六"]){
        playtypeID = 604;
        playIDnameLabel.text = @"组选六";
        playIDTips.text = @"最少选择3个号，猜对开奖号(顺序不限)即中173彩豆";
    }
    //set all views show
    if (playtypeID == 602) {
        label1.hidden = NO;
        label2.hidden = NO;
        label3.hidden = NO;
        firstImagebg.image = [UIImage imageNamed:@"jdd_pmbj.png"];
        for (UIView *subView in self.view.subviews) {
            if (subView.tag == 22 || subView.tag == 23 || subView.tag == 33 || subView.tag == 34) {
                subView.hidden = NO;
            }
        }
    }else{
        label1.hidden = YES;
        label2.hidden = YES;
        label3.hidden = YES;
        firstImagebg.image = [UIImage imageNamed:@"jdd_bjwpms.png"];
        for (UIView *subView in self.view.subviews) {
            if (subView.tag == 22 || subView.tag == 23 || subView.tag == 33 || subView.tag == 34) {
                subView.hidden = YES;
            }
        }
    }
    [self clearButtonClick:nil];
    [self setRbtnTitle:[NSString stringWithFormat:@"%@-%@",PAGE_FC3D_PICK_NUMBER,playIDnameLabel.text]];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)listSelect{
//    CGRect rect = [[UIScreen mainScreen] bounds];
//    rect.origin.x = (rect.size.width) / 2.0;
//    rect.origin.y = (rect.size.height) / 2.0;
//    rect.size.width = 251.0;
//    rect.size.height = 300.0;
//    indexList = [JddIndexListView getInstanceView];
//    [indexList setFrame:rect];
//    indexList.type = 0;
//    indexList.delegate = self;
//    [indexList show];
    NoticeViewController *noticeView = [[NoticeViewController alloc] init];
    noticeView.webInfoId = LOTTERY_TYPE_ID_FC3D;
    [self.navigationController pushViewController:noticeView animated:YES];
}

//-(void)selectorbutton1{
//    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_LOTTERY_OPEN_LIST
//                                                         fromController:self
//                                                             withObject:@"6"
//                                                            withObject2:nil];
//}
//
//-(void)selectorbutton2{
//    if (![JddCommonFunction isLogin]) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消", nil]
//        ;
//        [alert show];
//    }else {
//        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_BUY_HISTORY
//                                                             fromController:self
//                                                                 withObject:[NSNumber numberWithInt:LOTTERY_TYPE_ID_FC3D]
//                                                                withObject2:nil];
//    }
//}
//
//-(void)selectorbutton3{
//    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_HOW_TO_PLAY_SSQ
//                                                         fromController:self
//                                                             withObject:nil
//                                                            withObject2:nil];
//}
//
//-(void)selectorbutton4{
//    if (![JddCommonFunction isLogin]) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"玩球球"
//                                                        message:@"您还没有登录，请先登录"
//                                                       delegate:self
//                                              cancelButtonTitle:@"确定"
//                                              otherButtonTitles:@"取消", nil]
//        ;
//        [alert show];
//    }else {
//        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_FOLLOW_NUMBER_HISTORY
//                                                             fromController:self
//                                                                 withObject:nil
//                                                                withObject2:nil];
//    }
//}

- (void)QueryDigitalLotteryIssueOperationResult:(NSData *)result{
    if (result) {
        if ([JddDataParser parseLotteryIssueResult:result lotteryIssue:currentLotteryIssue]){
            issueCodeLabel.text = [NSString stringWithFormat:@"第%@期",currentLotteryIssue.name];
            endTime = [JddCommonFunction dateFromString:currentLotteryIssue.endTime];
            currentTime = [JddCommonFunction dateFromString:currentLotteryIssue.currentTime];
            
            countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1
                                                              target:self
                                                            selector:@selector(countDownTimer:)
                                                            userInfo:nil
                                                             repeats:YES];
        }
    }
}

- (void)countDownTimer:(NSTimer*)thisTimer{
    currentTime = [currentTime dateByAddingTimeInterval:1];
    
    NSTimeInterval interval = [endTime timeIntervalSinceDate:currentTime];
    if (interval == 1) {
        querystate = YES;
        interval = 0;
        [self startQuery];
        return;
        
    } else if(interval>1) {
        NSInteger remainDay = interval / 86400;
        NSInteger remainHour = (interval - 86400 * remainDay) / 3600;
        NSInteger remainMinute = (interval - 86400 * remainDay - remainHour * 3600) / 60;
        NSInteger remainSecond = (interval - 86400 * remainDay - remainHour *3600 - remainMinute * 60);
        remainTimeLabel.text = [NSString stringWithFormat:@"%d天%d小时%d分%d秒", remainDay, remainHour, remainMinute, remainSecond];
    }
}

-(void)startQuery{
    [countDownTimer invalidate];
    if (querystate==YES) {
        querystate = NO;
        JddQueryDigitalLotteryIssueOperation *operation = [[JddQueryDigitalLotteryIssueOperation alloc] init];
        operation.delegate = self;
        operation.lotteryTypeId = @"6";
        [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    }
}


//设置彩种，后进行刷新数据
- (void)setLotteryContent:(NSInteger)tag{
    
    
    _floatLayerIndex = tag;
    [_layer loadFloatLayer:_playMethodArr withIndex:_floatLayerIndex];
    NSString *title = [_playMethodArr objectAtIndex:_floatLayerIndex];
    [self selectMatchFC3D:title];
    
}

-(void)changePlayIDClick:(id)sender{
    if (!_playMethodArr) {
        _playMethodArr = [[NSMutableArray alloc] initWithObjects:@"直选",@"组选三",@"组选六", nil];
    }
    //NSArray *playMethod = [[NSArray alloc] initWithObjects:@"任选一",@"任选二",@"任选三",@"任选四",@"任选五",@"任选六",@"任选七",@"任选八",@"前二直选",@"前三直选",@"前二组选",@"前三组选", nil];
    
    if (!_layer) {
        _layer = [[FloatLayer alloc] initWithFloatLayer:FloatLayerTogetherBuy withLayerCallBack:^(NSInteger index) {
            [self setLotteryContent:index];
        }];
    }
    
    [_layer loadFloatLayer:_playMethodArr withIndex:_floatLayerIndex];
    /*
    NSArray *playMethod = [[NSArray alloc] initWithObjects:@"直选",@"组选三",@"组选六", nil];
    methodPick = [JddComboBoxView getInstanceView];
    methodPick.dataListTable.frame = CGRectMake(50, 90, 220, 140);
    methodPick.dataArray = [NSArray arrayWithArray:playMethod];
    methodPick.type = 1;
    methodPick.commitButton.hidden = YES;
    methodPick.commitLabel.hidden = NO;
    methodPick.delegate = self;
    [methodPick show];
     */
}
-(void)selectPlayMethodButtonClicked{
    [self changePlayIDClick:nil];
}

- (IBAction)clearButtonClick:(id)sender {
    [lotteryNumber clear];
    zhushuLabel.text = @"0注";
    moneyLabel.text = @"0彩豆";
    for (UIView *subView in self.view.subviews) {
        if ([[subView class] isSubclassOfClass:[UIButton class]] ||
            subView.tag == 11||subView.tag == 22 ||subView.tag == 33) {
            [((UIButton*)subView) setSelected:NO];
        }
    }
}
- (void)RandomSelectNumViewClickedButtonAtIndex:(NSNumber*)buttonIndex multiple:(NSNumber*)multiple{
    if ([buttonIndex intValue]== 1) {
        
        [lotteryNumberArray removeAllObjects];

        for (int i = 0; i < [multiple intValue]; ++i) {
            JddFc3dNumber *number = [[JddFc3dNumber alloc] init];
            switch (playtypeID) {
                case 602:
                    [number addBallNumber:arc4random()%10];
                    [number add2BallNumber:arc4random()%10];
                    [number add3BallNumber:arc4random()%10];
                    break;
                case 605://组选三 至少选2个数字
                    for (int i=0; i<2; i++) {
                        BOOL redo = NO;
                        do {
                            redo = NO;
                            NSInteger ranInt = 0;
                            ranInt = arc4random()%10;
                            if ([number BallHasNumber:ranInt]) {
                                redo = YES;
                            }else{
                                [number addBallNumber:ranInt];
                            }
                        } while (YES == redo);
                    }
                    break;
                case 604://组选六 至少选3个数字
                    for (int i=0; i<3; i++) {
                        BOOL redo = NO;
                        do {
                            redo = NO;
                            NSInteger ranInt = 0;
                            ranInt = arc4random()%10;
                            if ([number BallHasNumber:ranInt]) {
                                redo = YES;
                            }else{
                                [number addBallNumber:ranInt];
                            }
                        } while (YES == redo);
                    }
                    break;
                default:
                    break;
            }
            [lotteryNumberArray addObject:number];
        }
        NSNumber *playMethod = [NSNumber numberWithInt:playtypeID];
        [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PICK_NUM_FC3D_LIST fromController:self withObject:lotteryNumberArray withObject2:playMethod];
    }
}
- (IBAction)randomButtonClick:(id)sender {
//    CGRect rect = [[UIScreen mainScreen] bounds];
//    rect.origin.x = (rect.size.width - 251) / 2.0;
//    rect.origin.y = (rect.size.height - 139) / 2.0;
//    rect.size.width = 251.0;
//    rect.size.height = 139.0;
//    randomSelectNumberDialog = [JddRandomSelectNumView getInstanceView];
//    [randomSelectNumberDialog setFrame:rect];
//    randomSelectNumberDialog.type =1;
//    randomSelectNumberDialog.delegate = self;
//    [randomSelectNumberDialog show];
    
    [lotteryNumberArray removeAllObjects];
    for (int i = 0; i < 5; ++i) {
        JddFc3dNumber *number = [[JddFc3dNumber alloc] init];
        switch (playtypeID) {
            case 602:
                [number addBallNumber:arc4random()%10];
                [number add2BallNumber:arc4random()%10];
                [number add3BallNumber:arc4random()%10];
                break;
            case 605://组选三 至少选2个数字
                for (int i=0; i<2; i++) {
                    BOOL redo = NO;
                    do {
                        redo = NO;
                        NSInteger ranInt = 0;
                        ranInt = arc4random()%10;
                        if ([number BallHasNumber:ranInt]) {
                            redo = YES;
                        }else{
                            [number addBallNumber:ranInt];
                        }
                    } while (YES == redo);
                }
                break;
            case 604://组选六 至少选3个数字
                for (int i=0; i<3; i++) {
                    BOOL redo = NO;
                    do {
                        redo = NO;
                        NSInteger ranInt = 0;
                        ranInt = arc4random()%10;
                        if ([number BallHasNumber:ranInt]) {
                            redo = YES;
                        }else{
                            [number addBallNumber:ranInt];
                        }
                    } while (YES == redo);
                }
                break;
            default:
                break;
        }
        [lotteryNumberArray addObject:number];
    }
    NSNumber *playMethod = [NSNumber numberWithInt:playtypeID];
    [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PICK_NUM_FC3D_LIST fromController:self withObject:lotteryNumberArray withObject2:playMethod];
    

}

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
    
    
    static NSDate *shakeStart;
    NSDate *now = [[NSDate alloc] init];
    NSDate *checkDate = [[NSDate alloc] initWithTimeInterval:1.5f sinceDate:shakeStart];
    if ([now compare:checkDate] == NSOrderedDescending || shakeStart == nil){
        shakeCount = 0;
        shakeStart = [[NSDate alloc] init];
    }
    
    if (!sharked&&(fabsf(acceleration.x) > 1.0 || fabsf(acceleration.y) > 1.0 || fabsf(acceleration.z) > 1.1)){
        shakeCount++;
    }
    
    if (shakeCount > 0){
        shakeCount = 0;
        shakeStart = [[NSDate alloc] init];
        
        [self clearButtonClick:nil];
        switch (playtypeID) {
            case 602:
                [lotteryNumber addBallNumber:arc4random()%10];
                [lotteryNumber add2BallNumber:arc4random()%10];
                [lotteryNumber add3BallNumber:arc4random()%10];
                for (UIView* inView in self.view.subviews) {
                    if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                        [((UIButton*)inView) setSelected:YES];
                    }else if (inView.tag == 22 && [lotteryNumber Ball2HasNumber:[((UIButton*)inView).titleLabel.text intValue]]){
                        [((UIButton*)inView) setSelected:YES];
                    }else if (inView.tag == 33 && [lotteryNumber Ball3HasNumber:[((UIButton*)inView).titleLabel.text intValue]]){
                        [((UIButton*)inView) setSelected:YES];
                    }
                }
                break;
            case 605://组选三 至少选2个数字
                for (int i=0; i<2; i++) {
                    BOOL redo = NO;
                    do {
                        redo = NO;
                        NSInteger ranInt = 0;
                        ranInt = arc4random()%10;
                        if ([lotteryNumber BallHasNumber:ranInt]) {
                            redo = YES;
                        }else{
                            [lotteryNumber addBallNumber:ranInt];
                        }
                    } while (YES == redo);
                }
                for (UIView* inView in self.view.subviews) {
                    if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                        [((UIButton*)inView) setSelected:YES];
                    }
                }
                break;
            case 604://组选六 至少选3个数字
                for (int i=0; i<3; i++) {
                    BOOL redo = NO;
                    do {
                        redo = NO;
                        NSInteger ranInt = 0;
                        ranInt = arc4random()%10;
                        if ([lotteryNumber BallHasNumber:ranInt]) {
                            redo = YES;
                        }else{
                            [lotteryNumber addBallNumber:ranInt];
                        }
                    } while (YES == redo);
                }
                for (UIView* inView in self.view.subviews) {
                    if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                        [((UIButton*)inView) setSelected:YES];
                    }
                }
                break;
            default:
                break;
        }
        [self countMoney];

        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    }
    
}

- (IBAction)doneButtonClick:(id)sender {
    if([[JddPickNumFC3DListViewController sharedInstance].lotNumListTableView numberOfRowsInSection:0]>0){
        if([moneyLabel.text intValue] <= 0){
            NSNumber *playMethod = [NSNumber numberWithInt:playtypeID];
             [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PICK_NUM_FC3D_LIST fromController:self withObject:nil withObject2:playMethod];
        }else{
            NSNumber *playMethod = [NSNumber numberWithInt:playtypeID];
            [lotteryNumberArray removeAllObjects];
            JddFc3dNumber *newNum = [[JddFc3dNumber alloc] init];
            [newNum.BallArray addObjectsFromArray:lotteryNumber.BallArray];
            [newNum.SecondBallArray addObjectsFromArray:lotteryNumber.SecondBallArray];
            [newNum.ThirdBallArray addObjectsFromArray:lotteryNumber.ThirdBallArray];
            [lotteryNumberArray addObject:newNum];
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PICK_NUM_FC3D_LIST fromController:self withObject:lotteryNumberArray withObject2:playMethod];
        }
    }else{
        if([moneyLabel.text intValue] <= 0){
            switch (playtypeID) {
                case 602:
                    [JddCommonFunction messageBoxWithMessage:FC3D_ZHX_TIP];
                    break;
                case 605:
                    [JddCommonFunction messageBoxWithMessage:FC3D_ZX3_TIP];
                    break;
                case 604:
                    [JddCommonFunction messageBoxWithMessage:FC3D_ZX6_TIP];
                    break;
                default:
                    break;
            }
        }else{
            NSNumber *playMethod = [NSNumber numberWithInt:playtypeID];
            [lotteryNumberArray removeAllObjects];
            JddFc3dNumber *newNum = [[JddFc3dNumber alloc] init];
            [newNum.BallArray addObjectsFromArray:lotteryNumber.BallArray];
            [newNum.SecondBallArray addObjectsFromArray:lotteryNumber.SecondBallArray];
            [newNum.ThirdBallArray addObjectsFromArray:lotteryNumber.ThirdBallArray];
            [lotteryNumberArray addObject:newNum];
            [[JddViewControllerManager sharedInstance] pushViewControllerWithIndex:CONTROLLER_PICK_NUM_FC3D_LIST fromController:self withObject:lotteryNumberArray withObject2:playMethod];
        }
    }
}

- (IBAction)randomOne:(id)sender {
    [self clearButtonClick:nil];
    switch (playtypeID) {
        case 602:
            [lotteryNumber addBallNumber:arc4random()%10];
            [lotteryNumber add2BallNumber:arc4random()%10];
            [lotteryNumber add3BallNumber:arc4random()%10];
            for (UIView* inView in self.view.subviews) {
                if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                    [((UIButton*)inView) setSelected:YES];
                    [JddCommonFunction animationViewWithZoomOutIn:inView delaySecond:0];
                }else if (inView.tag == 22 && [lotteryNumber Ball2HasNumber:[((UIButton*)inView).titleLabel.text intValue]]){
                    [((UIButton*)inView) setSelected:YES];
                                        [JddCommonFunction animationViewWithZoomOutIn:inView delaySecond:0];
                }else if (inView.tag == 33 && [lotteryNumber Ball3HasNumber:[((UIButton*)inView).titleLabel.text intValue]]){
                    [((UIButton*)inView) setSelected:YES];
                                        [JddCommonFunction animationViewWithZoomOutIn:inView delaySecond:0];
                }
            }
            break;
        case 605://组选三 至少选2个数字
            for (int i=0; i<2; i++) {
                BOOL redo = NO;
                do {
                    redo = NO;
                    NSInteger ranInt = 0;
                    ranInt = arc4random()%10;
                    if ([lotteryNumber BallHasNumber:ranInt]) {
                        redo = YES;
                    }else{
                        [lotteryNumber addBallNumber:ranInt];
                    }
                } while (YES == redo);
            }
            for (UIView* inView in self.view.subviews) {
                if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                    [((UIButton*)inView) setSelected:YES];
                                        [JddCommonFunction animationViewWithZoomOutIn:inView delaySecond:0];
                }
            }
            break;
        case 604://组选六 至少选3个数字
            for (int i=0; i<3; i++) {
                BOOL redo = NO;
                do {
                    redo = NO;
                    NSInteger ranInt = 0;
                    ranInt = arc4random()%10;
                    if ([lotteryNumber BallHasNumber:ranInt]) {
                        redo = YES;
                    }else{
                        [lotteryNumber addBallNumber:ranInt];
                    }
                } while (YES == redo);
            }
            for (UIView* inView in self.view.subviews) {
                if (inView.tag == 11 && [lotteryNumber BallHasNumber:[((UIButton*)inView).titleLabel.text intValue]]) {
                    [((UIButton*)inView) setSelected:YES];
                                        [JddCommonFunction animationViewWithZoomOutIn:inView delaySecond:0];
                }
            }
            break;
        default:
            break;
    }
    [self countMoney];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)destoryView{

    [lotteryNumber clear];
    playtypeID = 602;
    sharked = true;
    [self selectMatchFC3D:[NSMutableString stringWithString:@"直选"]];
    for (UIView *subView in self.view.subviews) {
        if (subView.tag == 11||subView.tag == 22 ||subView.tag == 33) {
            [((UIButton*)subView) setSelected:NO];
        }
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [MobClick beginLogPageView:@"FC3D"];
	[MobClick event:@"Lottery-FC3D"];
    
    sharked = false;
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0];
    [super viewWillAppear:animated];
    
    
    [countDownTimer invalidate];
    JddQueryDigitalLotteryIssueOperation *operation = [[JddQueryDigitalLotteryIssueOperation alloc] init];
    operation.delegate = self;
    operation.lotteryTypeId = @"6";
    shakeCount = 0;
    [[JddGlobalParameter sharedInstance].operationQueue addOperation:operation];
    [self randomOne:nil];
}

-(void)viewWillDisappear:(BOOL)animated{
    [MobClick endLogPageView:@"FC3D"];

    [UIAccelerometer sharedAccelerometer].delegate = nil;
    sharked = true;
}
- (void)loadNavBar
{
    UIButton *right = [UIButton buttonWithType:UIButtonTypeCustom];
    right.frame = CGRectMake(0, 0, 40, 30);
    [right setTitle:@"帮助" forState:UIControlStateNormal];
    right.titleLabel.font = [UIFont systemFontOfSize:15];
    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [right addTarget:self action:@selector(listSelect) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:right];
    
}
//- (void)backView
//{
//    [self.navigationController popViewControllerAnimated:YES];
//}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    label1.hidden = NO;
    label2.hidden = NO;
    label3.hidden = NO;
    playtypeID = 602;
//    [self.navigationItem setTitle:PAGE_FC3D_PICK_NUMBER];
    
        UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        customLab.backgroundColor = [UIColor clearColor];
        [customLab setText:PAGE_FC3D_PICK_NUMBER];
        customLab.textAlignment = NSTextAlignmentCenter;

        [customLab setTextColor:[UIColor whiteColor]];
        customLab.font = [UIFont systemFontOfSize:19];
        self.navigationItem.titleView = customLab;


    [self loadNavBar];
    currentLotteryIssue = [[JddLotteryIssue alloc] init];
    lotteryNumber = [[JddFc3dNumber alloc] init];
    lotteryNumberArray = [NSMutableArray array];
    
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0];
    
    for (UIView *subView in self.view.subviews) {
        if ([[subView class] isSubclassOfClass:[UIButton class]]) {
            NSInteger number = [((UIButton*)subView).titleLabel.text intValue];
            int tagnumber = ((UIButton*)subView).tag;
            if (number >= 0 && number < 10&&tagnumber==11) {
                [((UIButton*)subView) setBackgroundImage:[UIImage imageNamed:@"jdd_redbollselected"] forState:UIControlStateSelected];
                [((UIButton*)subView) setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            }if (number >= 0 && number < 10&&tagnumber==22) {
                [((UIButton*)subView) setBackgroundImage:[UIImage imageNamed:@"jdd_redbollselected"] forState:UIControlStateSelected];
                [((UIButton*)subView) setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            }if (number >= 0 && number < 10&&tagnumber==33) {
                [((UIButton*)subView) setBackgroundImage:[UIImage imageNamed:@"jdd_redbollselected"] forState:UIControlStateSelected];
                [((UIButton*)subView) setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
            }
        }
    }
    [self selectMatchFC3D:[NSMutableString stringWithString:@"直选"]];

    //添加下拉选择
    [self addMenuBtn];
}

-(void)addMenuBtn
{
    NSString *title = [NSString stringWithFormat:@"%@-直选",PAGE_FC3D_PICK_NUMBER];
    
    rv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-140, 30)];
    rBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rBtn addTarget:self action:@selector(selectPlayMethodButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [rBtn setTitle:title forState:UIControlStateNormal];
    rBtn.titleLabel.font = [UIFont systemFontOfSize: 19.0];
    [rBtn setFrame:CGRectMake(0, 2, 180, 19)];
    rBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    UIImage *rBtnImg = LOADIMAGE(@"navBar_down");
    rImv = [[UIImageView alloc] initWithImage:rBtnImg];
    [self setRightBtnImage:title];
    
    //创建的一个view，加入btn和图片
    [rv addSubview: rBtn];
    [rv addSubview:rImv];
    self.navigationItem.titleView = rv;
    
    //加入手势
    rImv.userInteractionEnabled = YES;
    UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectPlayMethodButtonClicked)];
    [rImv addGestureRecognizer:recognizer];
}

//计算rImv的坐标
-(void)setRightBtnImage:(NSString *)titleStr
{
    JddSportNumber *btntitle = [[JddSportNumber alloc] init];
    btntitle.titleStr = titleStr;
    CGFloat width = [btntitle customWidth:19 font:19];
    rBtn.center = CGPointMake(90, 15);
    CGRect frame = rBtn.frame;
    frame.origin.x = (rv.width - width - 23) / 2;
    frame.size.width = width;
    rBtn.frame = frame;
    [rImv setFrame:CGRectMake(rBtn.frame.origin.x + width + 3, 9, 20, 12)];
}

//选择彩种
-(void)setRbtnTitle:(NSString *)title
{
    [rBtn setTitle:title forState:UIControlStateNormal];
    [self setRightBtnImage:title];
}

- (void)viewDidUnload {
    sharked = TRUE;
    [self setIssueCodeLabel:nil];
    [self setRemainTimeLabel:nil];
    [self setPlayIDTips:nil];
    [self setLabel1:nil];
    [self setLabel2:nil];
    [self setLabel3:nil];
    [self setZhushuLabel:nil];
    [self setMoneyLabel:nil];
    [self setPlayIDnameLabel:nil];
    [self setFirstImagebg:nil];
    [super viewDidUnload];
}

@end
